﻿using System;
using System.Windows;
using Csla.Xaml;
using Accounting.Library;

namespace csla4Skeleton.UI.SL.NghiepVu.TaiSanCoDinh.DM_DoiTuongTHCP
{
    public partial class DM_DoiTuongTHCP_ListViewModel : ViewModel<DM_DoiTuongTHCPList>
    {
        public event EventHandler LoadCompleted;
        public DM_DoiTuongTHCP_ListViewModel(string mode)
        {
            BeginRefresh("GetDM_DoiTuongTHCPList", mode);

        }

        public void GetDM_DoiTuongTHCP_ListViewModel(string mode)
        {
            BeginRefresh("GetDM_DoiTuongTHCPList", mode);
        }

        protected override void OnRefreshed()
        {
            base.OnRefreshed();
            if (Model != null)
            {
               
                if (LoadCompleted != null)
                {
                    LoadCompleted(this, new EventArgs());
                }
            }
        }

        public static readonly DependencyProperty SelectedItemProperty =
          DependencyProperty.Register("SelectedItem", typeof(DM_DoiTuongTHCPInfo), typeof(DM_DoiTuongTHCP_ListViewModel), null);
        public DM_DoiTuongTHCPInfo SelectedItem
        {
            get { return (DM_DoiTuongTHCPInfo)GetValue(SelectedItemProperty); }
            set { SetValue(SelectedItemProperty, value); }
        }

        public void DeleteDM_DoiTuongTHCP(object sender, ExecuteEventArgs e)
        {
            if (e.MethodParameter != null)
            {
                //cast OrderID parameter
                int Khoa = Int16.Parse(e.MethodParameter.ToString());
                this.IsBusy = true;
                Accounting.Library.DM_DoiTuongTHCP.DeleteDM_DoiTuongTHCP(Khoa, (o, ex) =>
                {
                    BeginRefresh("GetDM_DoiTuongTHCPList",BusinessConfiguration.Configuration.GridViewFetchMode);
                });
                this.IsBusy = false;
            }
        }	
    }
}
